package service

import (
	"net/http"

	"gitee.com/zenpk/backend-demo/internal/dal"
	"gitee.com/zenpk/backend-demo/internal/dto"
	"gitee.com/zenpk/backend-demo/internal/middleware"
	"github.com/gin-gonic/gin"
)

type ReserveRecord struct{}

var reserveRecordDal dal.ReserveRecord

func (s *ReserveRecord) GetReserveRecord(c *gin.Context) {
	var reserveRecord []dal.ReserveRecord
	var req dto.GetReserveRecordReq
	//请求绑定json
	if err := c.ShouldBindJSON(&req); err != nil {
		middleware.Logger.Warn(err.Error())
		c.JSON(http.StatusOK, dto.GetReserveRecordResp{
			SuccessCode: 0,
			Msg:         err.Error(),
		})
		return
	}
	reserveRecord, err := reserveRecordDal.GetReserveRecord(req.StudentNum)

	if err != nil {
		middleware.Logger.Warn(err.Error())
		c.JSON(http.StatusOK, dto.GetReserveRecordResp{
			SuccessCode: 0,
			Msg:         err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, dto.GetReserveRecordResp{
		SuccessCode:   1,
		Msg:           "获取成功",
		StudentNum:    req.StudentNum,
		ReserveRecord: reserveRecord,
	})
}
